<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>

        body {
            margin: 0;
        }

        .container {
            height: 100vh;
            width: 100%;
            border: 3px solid red;
            box-sizing: border-box;
            overflow: auto;
        }

        .box {
            height: 50px;
            width: 300px;
            border: 10px solid blue;
            box-sizing: border-box;
            margin: 50px auto;
        }
        .box.fixed {
            position: fixed;
            top: 0;
            width: 100%;
            margin: 0;
        }

    </style>
</head>
<body>
    <div class="container">
        <div class="content">
            <div class="box"></div>
            hello world<br>hello world<br>hello world<br>hello world<br>hello world<br>hello world<br>hello world<br>hello world<br>hello world<br>hello world<br>hello world<br>hello world<br>hello world<br>hello world<br>hello world<br>hello world<br>hello world<br>hello world<br>hello world<br>hello world<br>hello world<br>hello world<br>hello world<br>hello world<br>hello world<br>hello world<br>hello world<br>hello world<br>hello world<br>hello world<br>hello world<br>hello world<br>hello world<br>hello world<br>hello world<br>hello world<br>hello world<br>hello world<br>hello world<br>hello world<br>hello world<br>hello world<br>hello world<br>hello world<br>hello world<br>hello world<br>hello world<br>hello world<br>hello world<br>hello world<br>hello world<br>hello world<br>hello world<br>hello world<br>hello world<br>hello world<br>hello world<br>
        </div>
    </div>

    <script>

        const container = document.querySelector('.container');
        const box = document.querySelector('.box');

        container.scrollTop = 200;

        // container.addEventListener('scroll', () => {
        //     box.setAttribute('class', `box ${ container.scrollTop > 50 ? 'fixed' : '' }`);
        // });

    </script>
</body>
</html>
